package com.itheima.appserver.controller;


import com.itheima.appserver.service.SoulService;
import com.itheima.commons.model.vo.AnswerVo;
import com.itheima.commons.model.vo.SoulVo;
import com.itheima.commons.model.vo.ReportVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("testSoul")
public class SoulController {

    @Autowired
    private SoulService soulService;

    /**
     * 问卷列表
     *
     * @return
     */
    @GetMapping
    public ResponseEntity<List<SoulVo>> SoulQuestionnaire() {
        try {
            List<SoulVo> questionnaireVoList = soulService.querySoulQustionsList();
            return ResponseEntity.ok(questionnaireVoList);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
    }

    /**
     * 提交问卷
     *
     * @param answer
     * @return
     */
    @PostMapping
    public ResponseEntity<String> TestSoul(@RequestBody Map<String, List<AnswerVo>> answer) {
        String id = soulService.SaveSoulAnswer(answer);
        return ResponseEntity.ok(id);
    }


    /**
     *灵魂测试结果
     * @param id
     * @return
     */
    @GetMapping("report/{id}")
    public ResponseEntity<ReportVo> TestResult(@PathVariable("id") String id) {
        ReportVo reportVo = soulService.queryReport(id);
        return ResponseEntity.ok(reportVo);
    }
}
